home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Essential Home & Business Collection
/
The Essential Home & Business Collection.iso
/
27
/
3
/
5
/
HP22D5.ZIP
/
EXTERN
/
BARCHART.C
< prev
next >
Wrap
Text File
|
1991-04-16
|
3KB
|
122 lines
#include <stdarg.h>
#include <graph.h>
#include "extern.h"
#define TOPMARGIN 30
#define BOTTOMMARGIN 30
#define LEFTMARGIN 120
#define RIGHTMARGIN 120
extern savemouse();
extern restoremouse();
extern hide();
extern show();
extern button();
pascal near barchart(bars,numbars)
int *bars;
int numbars;
{
int highest;
int i,width,startx,height,maxheight;
int between;
struct videoconfig config;
_setvideomode(_HRESBW);
_getvideoconfig(&config);
for (i=highest=0;i<numbars;i++) {
if (bars[i] > highest) highest = bars[i];
}
between = 24 - numbars;
width = (config.numxpixels - (LEFTMARGIN + RIGHTMARGIN) - ((numbars - 1) * between)) / numbars;
startx = LEFTMARGIN;
maxheight = config.numypixels - (TOPMARGIN + BOTTOMMARGIN);
_moveto(LEFTMARGIN - (between >> 1),config.numypixels - BOTTOMMARGIN);
_lineto(config.numxpixels - RIGHTMARGIN + (between >> 1),config.numypixels - BOTTOMMARGIN);
for (i=0;i<numbars;i++) {
height = (maxheight * bars[i]) / highest;
_rectangle(_GFILLINTERIOR,
startx,
(config.numypixels - TOPMARGIN) - height,
startx + width,
config.numypixels - BOTTOMMARGIN);
if (i < numbars - 1) {
_moveto(startx + width + (between >> 1),config.numypixels - BOTTOMMARGIN - 1);
_lineto(startx + width + (between >> 1),config.numypixels - BOTTOMMARGIN + 1);
}
startx += width + between;
}
}
#define MAXBARS 20
int bars[MAXBARS];
Bar(int NumArgs,HANDLE hNumbers,HANDLE hEndTime)
{
int numbars;
PTR p,s;
char c;
SHAREDPTR pShared;
PACKETPTR Screen;
MSG msg;
DWORD endtime;
if (NumArgs < 1 || NumArgs > 2) return(STOP);
numbars = 0;
p = deref(hNumbers);
while (*p && numbars <= MAXBARS) {
for (s=p;*p && *p != ',' && *p != '\r';p++);
c = *p;
*p = '\0';
bars[numbars++] = atoi(s);
*p = c;
if (*p) p++;
}
pShared = GetSharedArea();
Screen = pShared -> pVideoModes[0];
savemouse();
barchart(bars,numbars);
endtime = (NumArgs == 2) ? GetTime() + (htoi(hEndTime) / 55) : 0;
show();
do {
GetEvent(&msg);
if (endtime) if (GetTime() > endtime) break;
} while (msg.Event != EVENT_KEYPRESS && !button());
/* wait until the mouse buttons are released */
while (button());
/* hide the mouse */
hide();
(*Screen -> SetMode)();
Refresh();
restoremouse();
}
POOL pascal Pool[] = {
{"barChart", Bar, 0, HANDLER},
{NULL, NULL, 0, 0} };